package cn.tangsihai.mq._01_hello_mq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static final String QUEUE_HELLO_NAME = "QUEUE_HELLO_NAME";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("115.159.88.63");
        Connection connection = factory.newConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        // 创建队列
        channel.queueDeclare(QUEUE_HELLO_NAME, true, false, false, null);
        // 发送消息
        channel.basicPublish("", QUEUE_HELLO_NAME, null, "汤思海发送hello消息".getBytes());
        System.out.println("消息发送成功");
    }
}
